import { createSlice } from '@reduxjs/toolkit'
import { type MenuItem } from './type'
import { useMenuList } from '@/hooks/useMenu'

const menuStore = createSlice({
  name: 'menu',
  initialState: {
    menuList: useMenuList() as MenuItem[]
  },
  reducers: {
    setMenuList(state, action) {
      state.menuList = action.payload
    }
  }
})

// 导出userInfo的ts类型
export type MenuState = ReturnType<typeof menuStore.reducer>

// 解构出actionCreater函数
export const { setMenuList } = menuStore.actions

// 导出reducer
export default menuStore.reducer